// 高阶组件

import { Component } from 'react';

function withSubscription (WrappedComponent, selectData) {
    return class extends Component {
        constructor(props) {
            super(props);
            this.handleChange = this.handleChange.bind(this);
            this.dataSource = [];
            this.state = {
                data: selectData(this.dataSource, props)
            }
        }

        componentDidMount() {

        }

        handleChange() {
            this.setState({
                data: selectData(this.dataSource, this.props)
            });
        }

        render() {
            return <WrappedComponent data={this.state.data} {...this.props}/>
        }
    }
}

function Test(props) {
    return <div> {props.data} </div>
}

export default withSubscription(
    Test, 
    (data, props) => {
        data = [1,2,3,4];
        return data;
    }
)